import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AnswerTemplate } from './answerTemplate.entity';

@Injectable()
export class AnswerTemplateService {
  constructor(
    @InjectRepository(AnswerTemplate)
    private repository: Repository<AnswerTemplate>,
  ) {}

  findByWxUser(wx_user: string): Promise<AnswerTemplate[]> {
    return this.repository.find({
      where:{wx_user},
      order:{create_time:'desc'},
    });
  }

  findAll(): Promise<AnswerTemplate[]> {
    return this.repository.find();
  }

  findOne(id: number): Promise<AnswerTemplate> {
    return this.repository.findOne({where:{id}});
  }

  async create(data: AnswerTemplate): Promise<AnswerTemplate> {
    return await this.repository.save(data);
  }

  async update(data: AnswerTemplate): Promise<AnswerTemplate> {
    return await this.repository.save(data);
  }
}
